<form class="am-form" id="batchEditForm">
    <table class="am-table am-table-bordered am-table-radius am-table-hover">
        <tr>
            <th style="width:20%">升级包</th>
            <th style="width:20%">模块</th>
            <th>描述</th>
        </tr>
        <tr>
            <th></th>
            <th>
                <input type="text" class="" id="module_batch" maxlength="100" placeholder="批量填写模块名称">
            </th>
            <th>
                <input type="text" class="" id="description_batch" maxlength="400" placeholder="批量填写升级内容描述">
            </th>
        </tr>
        <% for(var i=0; i<packages.length; i++) {%>
            <tr>
                <td>
                    <%=packages[i].appname_en %>
                </td>
                <td>
                    <input type="text" role="module" role-module="<%=packages[i].id%>" value="<%=packages[i].module%>" maxlength="400" placeholder="模块名称">
                </td>
                <td>
                    <input type="text" role="description" role-description="<%=packages[i].id%>" value="<%=packages[i].description%>" maxlength="400" placeholder="升级内容描述">
                </td>
            </tr>
            <%}%>
    </table>
    <div style="text-align: center;">
        <button type="button" id="batchEditForm-save" class="am-btn am-btn-success am-radius">保存</button>
        <button type="button" id="batchEditForm-close" class="am-btn am-btn-default am-radius">关闭</button>
    </div>
</form>
<script type="text/javascript">
$(function() {
    $('#module_batch').keyup(function() {
        var val = $(this).val();
        $('#batchEditForm [role="module"]').val(val);
    });

    $('#description_batch').keyup(function() {
        var val = $(this).val();
        $('#batchEditForm [role="description"]').val(val);
    });

    $('#batchEditForm-save').click(function() {
        var packages = [];

        <% for(var i=0; i<packages.length; i++) {%>
        packages.push({
            id: '<%=packages[i].id%>',
            description: $('[role-description="<%=packages[i].id%>"]').val() || '',
            module: $('[role-module="<%=packages[i].id%>"]').val() || ''
        });
        <%}%>

        $.ajax({
            url: '/upgradePackage/doBatchUpPackage',
            dataType: "json",
            type: "post",
            data: 'packagesJson=' + JSON.stringify(packages),
            success: function(data) {
                zeroModal.closeAll();
                if (data.success) {
                    $.toast({ text: '批量修改成功！', showHideTransition: 'slide', icon: 'success', position: 'top-center' });
                } else {
                    $.toast({ text: '批量修改失败！', showHideTransition: 'slide', icon: 'error', position: 'top-center' });
                }
            }
        });
    });

    $('#batchEditForm-close').click(function() {
        zeroModal.closeAll();
    });
});
</script>